package com.itbbfx.service.department.impl;

import com.itbbfx.entity.Unit;
import com.itbbfx.mapper.DrugdictionaryMapper;
import com.itbbfx.mapper.UnitMapper;
import com.itbbfx.service.department.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UnitServiceImpl implements UnitService {
    @Resource
    private UnitMapper unitMapper;
    @Autowired
    private DrugdictionaryMapper drugdictionaryMapper;

    @Override
    public List<Unit> findAllUnit(Unit unit) {
        return unitMapper.findAllUnit(unit);
    }

    @Override
    public String deleteUnit(Integer unitId) {
        if(drugdictionaryMapper.countUnit(unitId) > 0){
            return "请确认无药品使用该计量单位后再删除！";
        }
        if (unitMapper.deleteUnit(unitId) > 0) {
            return "删除成功";
        }
        return "删除失败";
    }

    @Override
    public int addUnit(Unit unit) {
        return unitMapper.addUnit(unit);
    }


    @Override
    public int count(Unit unit) {
        return unitMapper.count(unit);
    }
}
